<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<div class='form-group'>
				<label class='col-md-2 control-label'>产品名称</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='产品名称' type='text' name='productName' id='productName' data-bv-notempty='true' data-bv-notempty-message='产品名称不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>产品类型</label>
				<div class='col-md-10'>
					<select name="categoryId" id="categoryId"  lay-verify="required" class='form-control input-sm' data-bv-notempty='true'>
	<!--					<option value="">请选择一个产品类型</option>-->
					</select>
				</div>
			</div>
			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
					    <button class="btn btn-primary" onclick="location.href='sysChanList.html'">返回</button>
						<button class="btn btn-primary" type="submit" onclick="add()">
							<i class="fa fa-save"></i> 保存
						</button>
					</div>
				</div>
			</div>

		</fieldset>
	</form>
</div>
	<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../js/jq.js"></script>
	<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script type="text/javascript">
		layui.use(['layer','laydate'], function(){
		    var layer = layui.layer;
		    showProductTypeList();
		});

		function showProductTypeList() {
			var htmls = "<option value=\"\">请选择一个产品类型</option>";
			$.ajax({
				type : 'get',
				url : '/sysEquipments/all',
				contentType: "application/json; charset=utf-8",
				data : null,
				success : function(data) {
					for (var x in data) {
						htmls += '<option value="'+data[x].id+'">'+data[x].val+'</option>';
					}
					$("#typeId").html(htmls);
				}
			});
		}

		function add() {
			$('#form').bootstrapValidator();
			var bootstrapValidator = $("#form").data('bootstrapValidator');
			bootstrapValidator.validate();
		    if(!bootstrapValidator.isValid()){
			   return;
		    }
		    
		    var formdata = $("#form").serializeObject();

			$.ajax({
				type : 'post',
				url : '/sysEquipments',
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(formdata),
				success : function(data) {
					if (data.success) {
						layer.msg("添加成功", {shift: -1, time: 1500}, function(){
							location.href = "sysEquipmentList.html";
						});
					} else {
						layer.msg(data.msg);
					}

				}
			});
		}



		
	</script>
</body>
</html>
